<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Action</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>


<input type="text" value="">


<form action="action.php?v=truncate" method="post">
<input type="submit" value="truncate">
</form>

<form action="action.php?v=import" method="post">
<input type="submit" value="import">
</form>

<form action="action.php?v=export" method="post">
<input type="submit" value="export">
</form>


<form action="action.php?v=truncateText" method="post">
<input type="submit" value="truncateText">
</form>

<form action="action.php?v=importText" method="post">
<input type="submit" value="importText">
</form>

<form action="action.php?v=exportText_csv" method="post">
<input type="submit" value="exportText_csv">
</form>

 <form action="action.php?v=import_dajia" method="post">
<input type="submit" value="import_dajia">
</form>
</html>
<?php 

if($_SERVER['REQUEST_METHOD']=='POST') 
{	
	echo $_SERVER['QUERY_STRING'];
	parse_str($_SERVER['QUERY_STRING']);
	echo $v."<br />";
	echo 'POST<br>';
	include_once($_SERVER['DOCUMENT_ROOT']."/RecJP/class/class.SqliteHelper.php");
	$s=new SqliteHelper();
	
	if($v=="truncate"){
		$pdo=$s->ExecWithTans(null,"delete from danci;",null,0);
		$p=array(":name"=>"danci");
		$pdo=$s->ExecWithTans($pdo,"update sqlite_sequence set seq=0 where name=:name;",$p,1);
		echo 'truncate ok<br>'; 
	}
	else if($v=="import")
	{
		include_once($_SERVER['DOCUMENT_ROOT']."/RecJP/class/class.FileHelper.php");
		$ftest=new FileHelper();
		$words=$ftest->getCsvFile("c:\kk2.csv");

		foreach ($words as $word)
		{
			if(trim($word[0])!=""){
			$p=array(":wordid"=>trim($word[0]),":word"=>trim($word[1]),":read"=>trim($word[2]),":species"=>trim($word[3]),":meaning"=>trim($word[4]),":lesson"=>trim($word[5]),":bookid"=>trim($word[6]));
			//print_r($p);
			$sql="insert into danci (wordid,word,read,meaning,lesson,species,bookid) values(:wordid,:word,:read,:meaning,:lesson,:species,:bookid)";
			$s->ExecNoTans($sql,$p);
			}
			echo "<br/>";
		}
		echo 'import ok<br>'; 
	}
	else if($v=="export")
	{
		$sql="select * from danci";
		$result=$s->Query($sql,null);
		
		foreach($result as $row){ 
			$string=$row["wordid"].",".$row["word"].",".$row["read"].",".$row["species"].",".$row["meaning"].",".$row["lesson"].",".$row["bookid"]."<br>";
			echo $string;
		} 
	}
	else if($v=="importText")
	{
		$content = file_get_contents('c:\text2.txt');
		$content = trim($content);
		$split= explode( "|",$content);
		//print_r($split);
		$i=24;
		foreach($split as $text)
		{ 
			if(trim($text)=="")
			{
				continue;
			}
			$i++;
			$kewen= explode("@",$text);
			$p=array(":title"=>trim($kewen[0]),":basicText"=>trim($kewen[1]),":mainText"=>trim($kewen[2]),":lesson"=>$i,":book"=>"�°��׼�������(�²�)");
			//print_r($p);
			$sql="insert into TextTable (title,basicText,mainText,lesson,book) values(:title,:basicText,:mainText,:lesson,:book)";
			$s->ExecNoTans($sql,$p);
			//print_r($kewen);
			echo "$sql<br><br>";
		}
	}
	else if($v=="truncateText")
	{
		$pdo=$s->ExecWithTans(null,"delete from TextTable;",null,0);
		$p=array(":name"=>"TextTable");
		$pdo=$s->ExecWithTans($pdo,"update sqlite_sequence set seq=0 where name=:name;",$p,1);
		echo 'truncate TextTable ok<br>'; 

	}
	else if($v=="exportText_csv")
	{
		$sql="select * from texttable";
		$result=$s->Query($sql,null);
		foreach($result as $row){ 
			$string=$row["book"].",".$row["lesson"].",".$row["title"].",".$row["basicText"].",".$row["mainText"]."<br>";
			echo $string;
		} 

	}
        else if($v=="import_dajia")
        {
            include_once($_SERVER['DOCUMENT_ROOT']."/RecJP/class/class.FileHelper.php");
		$ftest=new FileHelper();
		$words=$ftest->getCsvFile("c:\wordsdajia.csv");

		foreach ($words as $word)
		{
			if(trim($word[0])!=""){
			    
			$p=array(":wordid"=>trim($word[0]),":word"=>trim($word[2]),":read"=>trim($word[1]),":species"=>"",":meaning"=>trim($word[3]),":lesson"=>trim($word[4]),":book"=>trim($word[5]));
			//print_r($p);
			$sql="insert into danci (wordid,word,read,meaning,lesson,species,book) values(:wordid,:word,:read,:meaning,:lesson,:species,:book)";
			$s->ExecNoTans($sql,$p);
			}
			echo "<br/>";
		}
		echo 'import ok<br>'; 
        }
}
else
{  
  echo 'GET';
}
?>



